package com.app.couponsharelife.ui.main.nativelife.order.activity
import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import com.app.couponsharelife.R
import com.app.couponsharelife.base.BaseActivity
import com.app.couponsharelife.data.bean.OrderClassBean
import com.app.couponsharelife.ui.view.ScaleTransitionPagerTitleView
import com.app.couponsharelife.ui.viewfactory.ShopOrderFragFactory
import com.app.couponsharelife.utils.AppUtils
import kotlinx.android.synthetic.main.activity_shop_order.*
import kotlinx.android.synthetic.main.base_title_white.*
import net.lucode.hackware.magicindicator.ViewPagerHelper
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator
/**
 *Created by xct on 2019/3/13
 *Description:本地生活订单页面
 */
class ShopOrderActivity:BaseActivity() {
    private var shopOrderFragFactory:ShopOrderFragFactory?=null
    private var commonNavigator: CommonNavigator?=null
    private var classList= arrayListOf<OrderClassBean>()
    override val viewLayoutId: Int
        get() = R.layout.activity_shop_order

    override fun initViews() {
        AppUtils.initImmersionBar(this,true)
        basetitle_title.text="我的订单"
        basetitle_llclose.setOnClickListener { finish() }
        setViewPager()
    }
    private fun setList(){
        with(classList){
            add(OrderClassBean("0","0","全部"))
            add(OrderClassBean("1","1","待支付"))
            add(OrderClassBean("2","2","待核销"))
            add(OrderClassBean("3","3","已使用"))
            add(OrderClassBean("4","4","已退款"))
            add(OrderClassBean("5","5","已取消"))
        }
    }
    private fun setViewPager(){
        shopOrderFragFactory= ShopOrderFragFactory()
        setList()
        shopOrderfrag_viewpager.offscreenPageLimit=6
        shopOrderfrag_viewpager.adapter=object : FragmentPagerAdapter(supportFragmentManager){
            override fun getItem(position: Int): Fragment {
                return shopOrderFragFactory!!.createFragment(position,classList[position])
            }

            override fun getCount(): Int {
                return classList.size
            }

            override fun getPageTitle(position: Int): CharSequence? {
                return classList[position].name
            }
        }
        commonNavigator= CommonNavigator(this)
        //commonNavigator!!.isAdjustMode=true
        commonNavigator!!.adapter=object : CommonNavigatorAdapter(){
            override fun getTitleView(p0: Context, p1: Int): IPagerTitleView {
                val colorTransitionPagerTitleView= ScaleTransitionPagerTitleView(p0,1f)
                colorTransitionPagerTitleView.setPadding(40,0,40,0)
                colorTransitionPagerTitleView.normalColor = resources.getColor(R.color.gray99)
                colorTransitionPagerTitleView.textSize=16f
                colorTransitionPagerTitleView.paint.isFakeBoldText=true
                colorTransitionPagerTitleView.selectedColor = resources.getColor(R.color.act_main_bot_nav_select_text_color)
                colorTransitionPagerTitleView.text = classList[p1].name
                colorTransitionPagerTitleView.setOnClickListener { shopOrderfrag_viewpager.currentItem = p1 }
                return colorTransitionPagerTitleView
            }

            override fun getCount(): Int {
                return classList.size
            }

            override fun getIndicator(p0: Context?): IPagerIndicator? {
                val indicator= LinePagerIndicator(p0)
                indicator.setColors(resources.getColor(R.color.act_main_bot_nav_select_text_color))
                indicator.mode= LinePagerIndicator.MODE_WRAP_CONTENT
                return indicator
            }
        }
        shopOrderfrag_tablayout.navigator=commonNavigator
        ViewPagerHelper.bind(shopOrderfrag_tablayout, shopOrderfrag_viewpager)
    }
    override fun onDestroy() {
        super.onDestroy()
        AppUtils.destroyImmersionBar(this)
    }
}